﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using Practice___组合单选框绑定.Model;

namespace Practice___组合单选框绑定.ViewModel
{
    public class CombRadiosViewModel:ViewModelBase
    {
        public CombRadiosViewModel()
        {
            radios = new List<RadioModel>()
            {
                new RadioModel(){Content = "c#"},
                new RadioModel(){Content = "cpp"},
                new RadioModel(){Content = "python"},
                new RadioModel(){Content = "dart"},
                new RadioModel(){Content = "flutter"},
                new RadioModel(){Content = "wpf"},
                new RadioModel(){Content = "mvvm"}
            };
        }

		private RadioModel radio;

		public RadioModel Radio
		{
			get => radio;
            set
            {
                radio = value;
                RaisePropertyChanged(nameof(Radio));
            }
		}

		private List<RadioModel> radios;

		public List<RadioModel> Radios
		{
			get => radios;
            set
            {
                radios = value;
                RaisePropertyChanged(nameof(Radios));
            }
        }

        private RelayCommand radioCheckCommand;

        public RelayCommand RadioCheckCommand
        {
            get => radioCheckCommand ?? (radioCheckCommand = new RelayCommand(ExecuteRadioCheck));
            set => radioCheckCommand = value;
        }

        private void ExecuteRadioCheck()
        {
            Radio = Radios.First(r => r.IsChecked);
        }
    }
}
